<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商品状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择">
          <el-option
            v-for="item in statusList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="商品名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="商家名称" prop="merchantName">
        <el-input
          v-model="queryParams.merchantName"
          placeholder="请输入商家名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家电话" prop="merchantPhone">
        <el-input
          v-model="queryParams.merchantPhone"
          placeholder="请输入商家名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['smy:goods:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:goods:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-check"
          size="small"
          :disabled="multiple"
          @click="handleAudit('Y')"
          v-hasPermi="['smy:goods:audit']"
        >审核通过</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-close"
          size="small"
          :disabled="multiple"
          @click="handleAudit('N')"
          v-hasPermi="['smy:goods:audit']"
        >审核不通过</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:goods:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商品编号" align="center" prop="id" width="80" />
      <el-table-column label="商品名称" align="center" prop="name" width="300" />
      <el-table-column label="商品类型" align="center" prop="goodstype" width="80" >
        <template slot-scope="scope">
          <span v-if="scope.row.goodstype==='room'">房间</span>
          <span v-if="scope.row.goodstype==='dish'">套餐</span>
          <span v-if="scope.row.goodstype==='entertainment'">娱乐项目</span>
        </template>
      </el-table-column>
      <el-table-column label="商品封面" align="center" prop="defaultimage" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.defaultimage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="销售价格" align="center" prop="defaultprice" width="80" />
      <el-table-column label="商家名称" align="center" prop="merchantName" width="180" />
      <el-table-column label="创建日期" align="center" prop="createtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商品状态" align="center" prop="status" width="180">
        <template slot-scope="scope">
          <span v-if="scope.row.status===2">新建</span>
          <span v-if="scope.row.status===3">审核通过</span>
          <span v-if="scope.row.status===4">审核不通过</span>
          <span v-if="scope.row.status===5">已下架</span>
          <span v-if="scope.row.status===7">已删除</span>
        </template>
      </el-table-column>
      <el-table-column label="销售状态" align="center" prop="sellstatus" >
        <template slot-scope="scope">
          <span v-if="scope.row.status===3 && scope.row.sellstatus==='soldOut'">已下架</span>
          <span v-if="scope.row.status===3 && scope.row.sellstatus!=='soldOut'">已上架</span>
        </template>

      </el-table-column>

<!--      <el-table-column label="${comment}" align="center" prop="goodschannelId" />-->
<!--      <el-table-column label="${comment}" align="center" prop="merchantId" />-->

<!--      <el-table-column label="${comment}" align="center" prop="marketprice" />-->
<!--      <el-table-column label="${comment}" align="center" prop="qualificationimage" width="100">-->
<!--        <template slot-scope="scope">-->
<!--          <image-preview :src="scope.row.qualificationimage" :width="50" :height="50"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="${comment}" align="center" prop="store" />-->
<!--      <el-table-column label="${comment}" align="center" prop="applytime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.applytime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="${comment}" align="center" prop="checknote" />-->
<!--      <el-table-column label="${comment}" align="center" prop="checktime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.checktime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="${comment}" align="center" prop="recommend" />-->
<!--      <el-table-column label="${comment}" align="center" prop="salesvolume" />-->
<!--      <el-table-column label="${comment}" align="center" prop="postage" />-->
<!--      <el-table-column label="${comment}" align="center" prop="postagetype" />-->
<!--      <el-table-column label="${comment}" align="center" prop="havesku" />-->
<!--      <el-table-column label="${comment}" align="center" prop="attributechannelId" />-->
<!--      <el-table-column label="${comment}" align="center" prop="gram" />-->
<!--      <el-table-column label="${comment}" align="center" prop="freighttemplateId" />-->
<!--      <el-table-column label="${comment}" align="center" prop="bargainbegintime" />-->
<!--      <el-table-column label="${comment}" align="center" prop="bargainendtime" />-->
<!--      <el-table-column label="${comment}" align="center" prop="bargainprice" />-->
<!--      <el-table-column label="${comment}" align="center" prop="bargainstore" />-->
<!--      <el-table-column label="${comment}" align="center" prop="marketingtype" />-->
<!--      <el-table-column label="${comment}" align="center" prop="begindateofvalidity" />-->
<!--      <el-table-column label="${comment}" align="center" prop="enddateofvalidity" />-->
<!--      <el-table-column label="${comment}" align="center" prop="bargainstatus" />-->
<!--      <el-table-column label="${comment}" align="center" prop="bargainsalesvolume" />-->
<!--      <el-table-column label="${comment}" align="center" prop="seckillprice" />-->
<!--      <el-table-column label="${comment}" align="center" prop="seckillsalesvolume" />-->
<!--      <el-table-column label="${comment}" align="center" prop="seckillstatus" />-->
<!--      <el-table-column label="${comment}" align="center" prop="seckillstore" />-->
<!--      <el-table-column label="${comment}" align="center" prop="seckillsessionId" />-->
<!--      <el-table-column label="${comment}" align="center" prop="presellprice" />-->
<!--      <el-table-column label="${comment}" align="center" prop="presellretainagepaybegintime" />-->
<!--      <el-table-column label="${comment}" align="center" prop="presellretainagepayendtime" />-->
<!--      <el-table-column label="${comment}" align="center" prop="presellsalesvolume" />-->
<!--      <el-table-column label="${comment}" align="center" prop="presellstatus" />-->
<!--      <el-table-column label="${comment}" align="center" prop="presellsubscriptionpaybegintime" />-->
<!--      <el-table-column label="${comment}" align="center" prop="presellsubscriptionpayendtime" />-->
<!--      <el-table-column label="${comment}" align="center" prop="groupbookingbegintime" />-->
<!--      <el-table-column label="${comment}" align="center" prop="groupbookingcondition" />-->
<!--      <el-table-column label="${comment}" align="center" prop="groupbookingendtime" />-->
<!--      <el-table-column label="${comment}" align="center" prop="groupbookinglimit" />-->
<!--      <el-table-column label="${comment}" align="center" prop="groupbookingprice" />-->
<!--      <el-table-column label="${comment}" align="center" prop="groupbookingsalesvolume" />-->
<!--      <el-table-column label="${comment}" align="center" prop="groupbookingstatus" />-->
<!--      <el-table-column label="${comment}" align="center" prop="groupbookingtotal" />-->
<!--      <el-table-column label="${comment}" align="center" prop="groupbookingstore" />-->
<!--      <el-table-column label="${comment}" align="center" prop="issupplier" />-->
<!--      <el-table-column label="${comment}" align="center" prop="brandId" />-->
<!--      <el-table-column label="${comment}" align="center" prop="affiliatedunitvalue" />-->
<!--      <el-table-column label="${comment}" align="center" prop="havemultiunit" />-->
<!--      <el-table-column label="${comment}" align="center" prop="ultimateunitvalue" />-->
<!--      <el-table-column label="${comment}" align="center" prop="affiliatedunitId" />-->
<!--      <el-table-column label="${comment}" align="center" prop="ultimateunitId" />-->
<!--      <el-table-column label="${comment}" align="center" prop="unitId" />-->
<!--      <el-table-column label="${comment}" align="center" prop="supplierpostage" />-->
<!--      <el-table-column label="${comment}" align="center" prop="supplierpostagetype" />-->
<!--      <el-table-column label="${comment}" align="center" prop="supplierfreighttemplateId" />-->
<!--      <el-table-column label="${comment}" align="center" prop="recommendsupplier" />-->
<!--      <el-table-column label="${comment}" align="center" prop="isissuingtype" />-->
<!--      <el-table-column label="${comment}" align="center" prop="issuinggoodsId" />-->
<!--      <el-table-column label="${comment}" align="center" prop="recommendtime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.recommendtime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->

<!--      <el-table-column label="${comment}" align="center" prop="rankno" />-->
<!--      <el-table-column label="${comment}" align="center" prop="dishcount" />-->
<!--      <el-table-column label="${comment}" align="center" prop="provideballoon" />-->
<!--      <el-table-column label="${comment}" align="center" prop="providechair" />-->
<!--      <el-table-column label="${comment}" align="center" prop="provideclean" />-->
<!--      <el-table-column label="${comment}" align="center" prop="tableservicenum" />-->
<!--      <el-table-column label="${comment}" align="center" prop="tablemax" />-->
<!--      <el-table-column label="${comment}" align="center" prop="provideinvoice" />-->
<!--      <el-table-column label="${comment}" align="center" prop="nomaterial" />-->
<!--      <el-table-column label="${comment}" align="center" prop="nomaterialprice" />-->
<!--      <el-table-column label="${comment}" align="center" prop="withmaterial" />-->
<!--      <el-table-column label="${comment}" align="center" prop="withmaterialprice" />-->
<!--      <el-table-column label="${comment}" align="center" prop="goodstype" />-->
<!--      <el-table-column label="${comment}" align="center" prop="providebreakfast" />-->
<!--      <el-table-column label="${comment}" align="center" prop="roomtype" />-->
<!--      <el-table-column label="${comment}" align="center" prop="shopcostprice" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['smy:goods:edit']"
          >修改</el-button>
          <el-button
            size="small"
            type="warning"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:goods:remove']"
            v-if="scope.row.status !==3 && scope.row.sellstatus !=='onSale'"
          >删除</el-button>
          <el-button
            size="small"
            type="success"
            icon="el-icon-top"
            @click="handleSellStatus(scope.row,'Y')"
            v-hasPermi="['smy:goods:status']"
            v-if="scope.row.status ===3 && scope.row.sellstatus ==='soldOut'"
          >上架</el-button>
          <el-button
            size="small"
            type="danger"
            icon="el-icon-bottom"
            @click="handleSellStatus(scope.row,'N')"
            v-hasPermi="['smy:goods:status']"
            v-if="scope.row.status ===3 && scope.row.sellstatus !=='soldOut'"
          >下架</el-button>
          <el-button
            size="small"
            type="info"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['smy:goods:detail']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="商品名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入商品名称" :disabled="form.id" />
        </el-form-item>
        <el-form-item label="包工不包料价格" prop="nomaterialprice" v-if="form.goodstype==='dish'">
          <el-input v-model="form.nomaterialprice" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="包工包料价格" prop="withmaterialprice" v-if="form.goodstype==='dish'">
          <el-input v-model="form.withmaterialprice" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="销售价格" prop="withmaterialprice" v-if="form.goodstype!=='dish'">
          <el-input v-model="form.withmaterialprice" placeholder="请输入销售价格" />
        </el-form-item>
        <el-form-item label="商品封面">
          <image-upload v-model="form.defaultimage" :limit="1"/>
        </el-form-item>
        <el-form-item label="商品相册">
          <!--            v-model="this.imageUrlList" -->
          <image-upload v-model="form.goodsImageList"

            :limit="99"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGoods, getGoods, delGoods, addGoods, updateGoods,auditGoods,changeSellStatus,goodsDetail } from "@/api/smy/mallGoods";

export default {
  name: "Goods",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      goodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      imageUrlList:[],
      statusList:[
        {value: '1', label: '待上架'},
        {value: '2', label: '新建'},
        {value: '3', label: '审核通过'},
        {value: '4', label: '审核不通过'},
        {value: '5', label: '已下架'},
        {value: '6', label: '已售罄'},
        {value: '7', label: '已删除'},
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        content: null,
        createtime: null,
        defaultimage: null,
        goodsno: null,
        name: null,
        status: null,
        goodschannelId: null,
        merchantId: null,
        defaultprice: null,
        marketprice: null,
        qualificationimage: null,
        store: null,
        applytime: null,
        checknote: null,
        checktime: null,
        recommend: null,
        salesvolume: null,
        postage: null,
        postagetype: null,
        havesku: null,
        attributechannelId: null,
        gram: null,
        freighttemplateId: null,
        bargainbegintime: null,
        bargainendtime: null,
        bargainprice: null,
        bargainstore: null,
        marketingtype: null,
        begindateofvalidity: null,
        enddateofvalidity: null,
        bargainstatus: null,
        bargainsalesvolume: null,
        seckillprice: null,
        seckillsalesvolume: null,
        seckillstatus: null,
        seckillstore: null,
        seckillsessionId: null,
        presellprice: null,
        presellretainagepaybegintime: null,
        presellretainagepayendtime: null,
        presellsalesvolume: null,
        presellstatus: null,
        presellsubscriptionpaybegintime: null,
        presellsubscriptionpayendtime: null,
        groupbookingbegintime: null,
        groupbookingcondition: null,
        groupbookingendtime: null,
        groupbookinglimit: null,
        groupbookingprice: null,
        groupbookingsalesvolume: null,
        groupbookingstatus: null,
        groupbookingtotal: null,
        groupbookingstore: null,
        issupplier: null,
        brandId: null,
        affiliatedunitvalue: null,
        havemultiunit: null,
        ultimateunitvalue: null,
        affiliatedunitId: null,
        ultimateunitId: null,
        unitId: null,
        supplierpostage: null,
        supplierpostagetype: null,
        supplierfreighttemplateId: null,
        recommendsupplier: null,
        isissuingtype: null,
        issuinggoodsId: null,
        recommendtime: null,
        sellstatus: null,
        rankno: null,
        dishcount: null,
        provideballoon: null,
        providechair: null,
        provideclean: null,
        tableservicenum: null,
        tablemax: null,
        provideinvoice: null,
        nomaterial: null,
        nomaterialprice: null,
        withmaterial: null,
        withmaterialprice: null,
        goodstype: null,
        providebreakfast: null,
        roomtype: null,
        shopcostprice: null
      },
      // 表单参数
      form: {

        goodsParamsList:[],
      },
      // 表单校验
      rules: {
        status: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        defaultprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        marketprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        store: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        recommend: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        salesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        postage: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        postagetype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
        havesku: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        gram: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        bargainprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        bargainstore: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        marketingtype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
        bargainstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        bargainsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillstore: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        presellprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        presellsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        presellstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingcondition: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookinglimit: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingtotal: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingstore: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        issupplier: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        affiliatedunitvalue: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        havemultiunit: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        ultimateunitvalue: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        supplierpostage: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        supplierpostagetype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
        recommendsupplier: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        isissuingtype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listGoods(this.queryParams).then(response => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        content: null,
        createtime: null,
        defaultimage: null,
        goodsno: null,
        name: null,
        status: 0,
        goodschannelId: null,
        merchantId: null,
        defaultprice: null,
        marketprice: null,
        qualificationimage: null,
        store: null,
        applytime: null,
        checknote: null,
        checktime: null,
        recommend: null,
        salesvolume: null,
        postage: null,
        postagetype: null,
        havesku: null,
        attributechannelId: null,
        gram: null,
        freighttemplateId: null,
        bargainbegintime: null,
        bargainendtime: null,
        bargainprice: null,
        bargainstore: null,
        marketingtype: null,
        begindateofvalidity: null,
        enddateofvalidity: null,
        bargainstatus: 0,
        bargainsalesvolume: null,
        seckillprice: null,
        seckillsalesvolume: null,
        seckillstatus: 0,
        seckillstore: null,
        seckillsessionId: null,
        presellprice: null,
        presellretainagepaybegintime: null,
        presellretainagepayendtime: null,
        presellsalesvolume: null,
        presellstatus: 0,
        presellsubscriptionpaybegintime: null,
        presellsubscriptionpayendtime: null,
        groupbookingbegintime: null,
        groupbookingcondition: null,
        groupbookingendtime: null,
        groupbookinglimit: null,
        groupbookingprice: null,
        groupbookingsalesvolume: null,
        groupbookingstatus: 0,
        groupbookingtotal: null,
        groupbookingstore: null,
        issupplier: null,
        brandId: null,
        affiliatedunitvalue: null,
        havemultiunit: null,
        ultimateunitvalue: null,
        affiliatedunitId: null,
        ultimateunitId: null,
        unitId: null,
        supplierpostage: null,
        supplierpostagetype: null,
        supplierfreighttemplateId: null,
        recommendsupplier: null,
        isissuingtype: null,
        issuinggoodsId: null,
        recommendtime: null,
        sellstatus: "0",
        rankno: null,
        dishcount: null,
        provideballoon: null,
        providechair: null,
        provideclean: null,
        tableservicenum: null,
        tablemax: null,
        provideinvoice: null,
        nomaterial: null,
        nomaterialprice: null,
        withmaterial: null,
        withmaterialprice: null,
        goodstype: null,
        providebreakfast: null,
        roomtype: null,
        shopcostprice: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增商品操作 */
    handleAdd() {
      //跳转到新增商品页面
      this.$router.push("/mallGoods/goodsAdd");
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      goodsDetail({id}).then(response => {
        this.form = response.data;
        // const goodsImageList = response.data.goodsImageList || [];
        // let imageUrlList = [];
        // if(goodsImageList.length>0){
        //   goodsImageList.forEach(item=>{
        //     imageUrlList.push(item.name);
        //   })
        // }
        // this.form.imageUrlList = imageUrlList;


        this.open = true;
        this.title = "修改商品信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            let imageUrlList = this.form.goodsImageList;
            let goodsImageList = [];
            if(imageUrlList.length>0){
              imageUrlList.forEach(item=>{
                goodsImageList.push({name:item.name})
              })
            }
            this.form.goodsImageList = goodsImageList;

            updateGoods(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGoods(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //批量审核通过
    handleAudit(auditType) {
      const ids = this.ids;
      let longIdList = [];
      this.ids.forEach(item=>{
        longIdList.push(item);
      })
      const auditDto = {
        longIdList,
        optType:auditType
      }
      let message = "是否确认审核";
      if(auditType==='Y'){
        message+="通过选择的"+ids.length+"条商品信息";
      }
      if(auditType==='N'){
        message+="不通过选择的"+ids.length+"条商品信息";
      }
      this.$modal.confirm(message).then(function() {
        return auditGoods(auditDto);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    //设置商品上架、下架
    handleSellStatus(row,optType){
      let longIdList = [];
      longIdList.push(row.id);
      const optDto = {
        longIdList,
        optType
      }
      let message = "是否确认";
      if(optType==='Y'){
        message+='上架名称为"'+row.name+'"的商品？';
      }
      if(optType==='N'){
        message+='下架名称为"'+row.name+'"的商品？';
      }
      this.$modal.confirm(message).then(function() {
        return changeSellStatus(optDto);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    //跳转到商品详情页面
    handleDetail(row){
      this.$router.push("/mallGoods/goodsDetail?goodsId="+row.id);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商品名称为"' + row.name + '"的数据项？').then(function() {
        return delGoods(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/goods/export', {
        ...this.queryParams
      }, `goods_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
